# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=assimp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.0.1
pkgrel=3
pkgdesc="Portable Open Source library to import various well-known 3D model formats in an uniform manner (mingw-w64)"
arch=('any')
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-minizip"
         "${MINGW_PACKAGE_PREFIX}-zziplib"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
url="http://www.assimp.org"
source=(${_realname}-${pkgver}.tar.gz::https://github.com/assimp/assimp/archive/v${pkgver}.tar.gz
        build-fixes.patch
        mingw-cmake-targets.patch)
options=('!strip' 'staticlibs')
sha256sums=('11310ec1f2ad2cd46b95ba88faca8f7aaa1efe9aa12605c55e3de2b977b3dbfc'
            '8122b87256094833d8407ad8003c67916459e41472c5cfee58a55ed495d2f50c'
            'ce709ad48e9a623dc17480b15bf01c06c6c20a573c358d1768ddc676f706b210')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/build-fixes.patch
  patch -p1 -i ${srcdir}/mingw-cmake-targets.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=RELEASE \
    -DASSIMP_BUILD_ASSIMP_TOOLS=YES \
    -DASSIMP_BUILD_STATIC_LIB=OFF \
    -DASSIMP_BUILD_TESTS=OFF \
    -DDirectX_DXERR_LIBRARY=${MINGW_PREFIX}/${MINGW_CHOST}/lib/libdxerr9.a \
    ../${_realname}-${pkgver}
  make
}

package() {
  cd "${srcdir}//build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} -j1 install
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
